package com.example.example01;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class WordCountReducer extends Reducer<Text,IntWritable,Text,IntWritable>{
  private int sum = 0;
  private final Text kwriter = new Text();
  private final IntWritable vwriter = new IntWritable(1);
  
  public WordCountReducer(){}

  @Override
  public void reduce(Text key, Iterable<IntWritable> values,Context context) throws IOException, InterruptedException {
    for(IntWritable iw : values)
      this.sum += iw.get();
    kwriter.set(key.toString());
    vwriter.set(this.sum);
    context.write(key,vwriter);
  }
}
